package br.uniriotec.ppgi.leo.controller.run;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;

import br.uniriotec.ppgi.leo.controller.nlp.StanfordPreprocessor;
import br.uniriotec.ppgi.leo.controller.nlp.srl.LTHSemanticRoleLabeler;
import br.uniriotec.ppgi.leo.controller.utils.AppConfigurer;
import br.uniriotec.ppgi.leo.controller.utils.StringUtils;
import br.uniriotec.ppgi.leo.model.PreprocessedSentence;


/**
 * Simple class to run the standalone version.
 * 
 * @author Felipe Leao
 *
 */
public class LEOProcessor {
	private static Logger logger = Logger.getLogger(LEOProcessor.class);
	
	public void process(String filepath, String lth_srl_root) throws IOException{
		
		/*
		 * Carregar texto
		 * tokenizar texto
		 * Taggear sentencas
		 * Converter para formato aceito pelo SRL
		 * TODO Identificar termos relevantes a partir do Output
		 * TODO Realizar WSD e extrair Supersenses dos substantivos relevantes
		 */
		
		
		/* ************************************************
		 * 			Load Domain Description
		 * ************************************************/
		logger.info("## Loading domain description file...");
		
		AppConfigurer cfg = AppConfigurer.getInstance();
		String fileContent = StringUtils.removeLineBreaks(cfg.loadTextFile(filepath));
		
		
		
		/* ************************************************
		 * 			Pre-process text
		 * ************************************************/
		logger.info("## Pre-processing text...");
		List<PreprocessedSentence> processedText = StanfordPreprocessor.preprocessText(fileContent);
//		for(PreprocessedSentence s : processedText){
//			System.out.println(s.getFullSentence());
//			String words = "";
//			for(String w : s.getWords()){
//				words += "\""+w+"\", ";
//			}
//			System.out.println(words);
//		}
		
		/* ************************************************
		 * 			Label Semantic Roles
		 * ************************************************/
		logger.info("## DefineSemantic Roles...");
		
		/*
		 * find semantic roles
		 */
		LTHSemanticRoleLabeler srl = new LTHSemanticRoleLabeler(lth_srl_root);
		File inputFile = srl.tempInputFileBuilder(processedText);
//		File inputFile = srl.annotateSRL(processedText);
		
		String caminhoCoNLLFile = "/Users/felipeleao88/Desktop/inputTesteSRL.tokens";
		File outputFile = new File(caminhoCoNLLFile);
		FileUtils.copyFile(inputFile, outputFile);
		
		
	}
	

}
